<?php
class TestAction extends Action{
	public function _initialize() {
			//初始化用户相关常量，例如用户购物车信息，用户地区信息（通过地区显示相关产品），最新礼物等
			//这些操作是否应放在，Action中完成？
			//exit;
	}
	
	public function testRebate(){
		echo "11";
		$data = model("Agent")->searchRebate('1013','2011-12-01','Y');
		echo model("Agent")->getLastSql();
		dump($data);
		exit;
	}
	
	public function rebate(){
		$total = 100.20;
		$cashpayed = 50.0;
		$rebate = 2;
		$rebate_model='rebate_money'; //'rebate_percent','rebate_money'
		$result = countRebateValue($total,$cashpayed,$rebate,$rebate_model);
		echo $result;
		
		$agent_id = "1004";
		$order_id = "1001313215900053650";
		$orderinfo = M("Order")->where(array('id'=>$order_id))->find();
		
		//查询上架商品设置的兑换截止时间
		$shelf = M('GoodsShelf')->where(array('id'=>$orderinfo['shelf_id']))->find();
		
		
		$payinfos = service('Pay')->selectItemPay($order_id,'pay_order','Y','Y');
		
		//计算支付的总金额
		//$total_fee=service('Pay')->countOrderPaiedAmount($order_id,'pay_order','Y','Y');
		foreach($payinfos as $vop){
			$total_fee = $total_fee+$vop['total_fee'];
		}
				
		model('Agent')->addRebate($agent_id,$order_id,$total_fee,$orderinfo['paid_money']
									,$shelf['rebate_value'],$shelf['rebate_model']);
	}
	
	public function getMmsBg(){
		$shelfid = $_REQUEST['shelfid'];
		$result = service('SmsImg')->getMmsBg($shelfid);
		echo 'result='.$result.'<br>';
		echo '<img src="'.getAttachUrl($result).'"><br>';
		exit;
	}
	
	
	public function testQumo(){
		$v = 9%5;
		echo (40%18);
		echo (9/5);
	}
	
	public function testparsecoupon(){
		$order_id = $_REQUEST['oid'];
		$couponlist = service('Coupon')->select4UserTobeSendByOid($order_id);
		//dump($couponlist);
		$sendcenter = service('SendCenter');
		$senData = $sendcenter->parseCouponSendData($couponlist);
		dump($senData);
		//$sendcenter->send($senData);
		exit;
	}
	
	public function testrandom(){
		echo rand(0,10);
		exit;
	}
	
	public function testDict(){
		$paydict = service('Dict')->getAllDirectSubDicts('pay','code');
		dump($paydict);
		exit;
	}
	
	public function testselectPayinfo(){
		$oid = $_GET['oid'];
		$payinfos = service('Pay')->selectItemPay($oid,'pay_order');
		dump($payinfos);
		exit;
	}
	
	public function testextract(){
		$a = 'Original';
		$my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse");
		extract($my_array);
		echo "\$a = $a; \$b = $b; \$c = $c";
		exit;
	}
	
	public function testuaccount(){
		//$id = $_GET['id'];
		echo "starting";
		$uaccount = service('UserAccount')->get4User();
		dump($uaccount);
		exit;
	}
	
	
	public function _getIdFromItemId(){
		$itemId = $_GET['id'];
		$itemId1 = explode('-',$itemId);
		echo $itemId1[0];
		exit;
	}
	
	public function testdouble(){
		$money = $_GET['money'];
		$money = $money/100;
		echo sprintf("%01.2f",$money);
		exit;
	}
	
	
	public function refreshPhoneBook(){
		
	}
	
	
	public function refreshCouponGoodsID(){
		$coupons = M('Coupon')->findAll();
		foreach($coupons as $key=>$val){
			$order = M('Order')->where('id='.$val['order_id'])->find();
			$shelf = M('GoodsShelf')->where('id='.$order['shelf_id'])->find();
			$no = M('Coupon')->where('id='.$val['id'])->setField('goods_id', $shelf['goods_id']);
			echo $val['id']."->".$shelf['goods_id'];
			if($no)echo "success<br>";
			else echo "failed<br>";
		}
		exit;
	}
	
	
	public function refreshCouponCh(){
		$coupons = M('Coupon')->findAll();
		foreach($coupons as $key=>$val){
			$order = M('Order')->where('id='.$val['order_id'])->find();
			$shelf = M('GoodsShelf')->where('id='.$order['shelf_id'])->find();
			$no = M('Coupon')->where('id='.$val['id'])->setField('goods_id', $shelf['goods_id']);
			echo $val['id']."->".$shelf['goods_id'];
			if($no)echo "success<br>";
			else echo "failed<br>";
		}
		exit;
	}
	
	//rand(0,10)
	public function setCouponChecker(){
		$coupons = M('Coupon')->where('checker_id>0')->findAll();
		foreach($coupons as $key=>$val){
			$goods = M('Goods')->where('id='.$val['goods_id'])->find();
			$no = 0;
			if(!empty($goods)){
				$pdata = D('Partner','Admin')->selectPartnerInfo(array('porppid'=>$goods['partner_id']),'id',null,null);
				$ary_pids = getSubByKey($pdata,"id");
				if(count($ary_pids)>0){
					$index = rand(0,count($ary_pids)-1);
					$no = M('Coupon')->where('id='.$val['id'])->setField('checker_id', $ary_pids[$index]);
				}
			}
			echo $val['id']."->".$ary_pids[$index];
			if($no)echo "success<br>";
			else echo "failed<br>";
		}
		exit;
	}
	
	
	public function testtime(){
		$stime = 1304355026;
		$etime = time();
		echo    date("Y-m-d", strtotime("+1 years", $etime));
		echo    date("Y-m-d", strtotime("+1 years", strtotime("2010-10")));
		echo    date("Y-m-d", strtotime("+1 months", strtotime("2010-10")));
		$etime = paramMillisecond2Date(time(),'Y-m');
		$stime = "2010-10";
		echo $etime."<br>";
		$index = 0;
		while (true){
			$index++;
			echo $stime."<br>";
			if($etime==$stime||$index>20){
				break;
			}
			$stime = date("Y-m", strtotime("+1 months", strtotime($stime)) );
			
		}
		exit;
	}
	
	
	function testsendTa(){
		$product = service('Product')->getByShelfId('10016');
		$body=$this->_sendTAEmailBody($product,'sdsdsdsd');
		echo $body;
		exit;
	}
	
	
 private function _sendTAEmailBody($productdata,$sendname){
    	$basePublicPath = SITE_URL.'/Public';
		$goodsurl = SITE_URL.U('Product://Index/detailp',array('shelfid'=>$productdata['shelf_id']));
		$img = SITE_URL.getPhotoFromThumb($productdata['goods_icon'],250,250);
		$shelf_market_price = formatMoney($productdata['shelf_market_price']);
		$shelf_out_price 	= formatMoney($productdata['shelf_out_price']);
		$bsub_bsubpage 	= service('Brand')->search4UserBSub($productdata['partner_id'],$bsub_area_id,$bsub_city_id,null,20);
		$body = <<<EOD
<body>
<div class="blank10"></div>
<div style="width:100%; text-align:center; margin:0 auto; ">
	<div class="" style="font-size: 14px; line-height: 170%;">
		<div style="font-size: 14px; padding: 0pt; height: auto; font-family: 'lucida Grande', Verdana; margin-right: 0px;" >
			<div style="width: 524px; margin: 0 auto; text-align: center;">
				<div style="text-align: left; font-weight: bold;"><b class="green"></b>您的好友{$sendname}发送给您的：</div>
				<div style="text-align: left; font-size: 12px; margin: 4px 0 18px; line-height: 18px;">
					{$sendname}在小心意网站(<a href="www.xiaoxinyi.com" target="_blank" >www.xiaoxinyi.com</a>)
					上看到心仪的商品 【{$productdata['goods_title']}】，TA想到了你，希望你能够实现TA的愿望。
				</div>
			<div>
			<div style="border: 1px solid #488825; -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; float: left;">
				<a style="font-size: 14px; width: 150px; border: 2px solid #488825; -moz-border-radius: 3px; -khtml-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 1px; height: 24px; line-height: 24px; cursor: pointer; background: #62A026; color: #FFF; font-weight: bold; border: 1px solid #7CB04A; padding: 0 0 0px; display: block; text-decoration: none; text-align: center;"
					href="{$goodsurl}"	target="_blank">点击送给TA</a>
			</div>
			<div style="float: left; margin: 3px 0 0 15px;">（此邮件为系统发送，无需回复！）</div>
		</div>
		<div class="blank10"></div>
	</div>
	
	<div style="text-align: center;width: 100%">
		<div style="width: 540px;height:600px;margin:0px auto;background: url('{$basePublicPath}/Images/global/bg_sendTaEmail.jpg') no-repeat transparent;">
			<div class="primary_box">
				<div class="blank10"></div>	
				<!--商品概要信息展示，最右上侧-->
				<ul class="info" style="text-align:left;">
					<!--1. 商品名称-->
					<li class="name"><strong>{$productdata['goods_title']}</strong></li>
					<!--2. 商品品牌以及编号，可以定位到品牌页面，这里的商品品牌是不是使用图标比较好？-->
					<li>商品品牌：{$productdata['partner_title']}</li> 
					<!-- 
					<li>商品编号：<b><span id="goods_id">{$productdata['goods_id']}</span></b></li>
					 -->
					<!--3. 市场价，加删除线-->
					<li>市 场 价： <b class="price">{$shelf_market_price}</b></li>
					<!--4. 小心意价格-->
					<li>心 意 价： <span class="sell">{$shelf_out_price}</span></li>
					<li>兑换地点：
						<a class="info_a" href="{$goodsurl}" target="_blank" title="查看心意券能够兑换的所有连锁店地址">查看地点（北京 共2家分店）</a></li>
					
					<li >商品构成：{$productdata['goods_summary']}</li>
					<li class="br_line clear"></li>
				</ul>
		
		
				<!--商品图片展示，最左上侧-->
				<div class="pic">
					<!--1. 图片盒，目前共四张，用js来控制显示与否-->
					<div id="pic_box">
						<div style="float: left;text-align: center;overflow: hidden;border:0px solid #EBEBEB;">
							<a 	href="{$goodsurl}"  class="goods_b" target="_blank" title="{$productdata['goods_title']}" >
								<img src="{$img}" alt="{$productdata['goods_title']}">	
							</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<style>
HTML { }
BODY { margin: 0; color: #494949;font-size:12px; font-family:"微软雅黑"; /**font:9pt Tahoma,"微软雅黑", Arial,Helvetica,Sans-Serif;**/ line-height:14px; letter-spacing:0;}
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td,select{ padding: 0; margin: 0; }
UL,LI { padding:0; margin:0; list-style:none;}
IMG { border: none; padding: 0; margin: 0;}
input,img,select {vertical-align:middle;}

/* 公共样式表 */
* {margin:0;padding:0;}
input, select, option, textarea{margin:0;padding:0; font-size:12px;}
h1, h2, h3, h4, h5, h6 {font-size:14px;}
input{ padding:0px; margin:0px; font-size:12px;}

A {color: #1F71CB;font-size:12px;text-decoration:none}
A:link { color:#1F71CB; text-decoration: none;}
A:visited { color:#1F71CB; text-decoration: none;}
A:hover { color:#FF9900;}
.primary_box {
    float: left;
    margin: 10px 10px 10px 17px;
    width: 510px;
}
.pic {
    float: left;
    width: 250px;
}
#pic_box {
    height: 250px;
    overflow: hidden;
}
#pic_box div {
    display: block;
    height: 250px;
    left: 0;
    overflow: hidden;
    padding: 0;
    top: 0;
    width: 250px;
}
.info {
    color: #999999;
    display: block;
    float: right;
    font-family: Tahoma,Arial,Helvetica,sans-serif,SimSun;
    line-height: 28px;
    padding-right: 5px;
    width: 240px;
}
.info b {
    color: #999999;
    font-weight: normal;
}
.info strong {
    color: #666666;
}
.brand {
    color: #999999;
    font-size: 14px;
}
.name {
    border-bottom: 1px dashed #DEDEDE;
    color: #000000;
    font-size: 16px;
    margin-bottom: 5px;
    padding-bottom: 3px;
    padding-right: 5px;
}
.price {
    font-family: Arial,Helvetica,sans-serif;
    font-size: 12px;
    font-style: italic;
    text-decoration: line-through;
}
.sell {
    color: #D30200;
    font-family: Arial,Helvetica,sans-serif;
    font-size: 26px;
    font-weight: bold;
    line-height: 30px;
    padding-right: 5px;
}

.blank10 {
    clear: both;
    height: 10px;
    list-style: none outside none;
    margin: 0;
    overflow: hidden;
    padding: 0;
}
</style>
</body>
EOD;

		return $body;
    }
	
}
?>